package com.ws.test09.test;

import com.ws.test09.entity.Student;
import com.ws.test09.util.StudentComparable;
import com.ws.test09.util.StudentComparator;

import java.util.*;

/**
 * @author 王硕
 * @version jdk21
 * @className test
 * @description
 * @date 2024/11/21 21:38
 */
public class test {
    public static void main(String[] args) {
        List<StudentComparable> studentsComparable = new ArrayList<>();
        studentsComparable.add(new StudentComparable(1, "Alice", 20, 89.5));
        studentsComparable.add(new StudentComparable(2, "Bob", 22, 95.5));
        studentsComparable.add(new StudentComparable(3, "Charlie", 20, 95.5));
        studentsComparable.add(new StudentComparable(4, "David", 21, 90.0));
        studentsComparable.add(new StudentComparable(5, "Eve", 19, 88.5));
        studentsComparable.add(new StudentComparable(6, "Frank", 22, 95.5));

        // 使用Comparable排序
        Collections.sort(studentsComparable);
        System.out.println("使用Comparable排序：");
        for (StudentComparable student : studentsComparable) {
            System.out.println(student);
        }

        List<Student> students = new ArrayList<>();
        students.add(new Student(1, "Alice", 20, 89.5));
        students.add(new Student(2, "Bob", 22, 95.5));
        students.add(new Student(3, "Charlie", 20, 95.5));
        students.add(new Student(4, "David", 21, 90.0));
        students.add(new Student(5, "Eve", 19, 88.5));
        students.add(new Student(6, "Frank", 22, 95.5));

        // 使用Comparator排序
        Collections.sort(students, new StudentComparator());
        System.out.println("\n使用Comparator排序：");
        for (Student student : students) {
            System.out.println(student);
        }
    }
}
